package edu.gduf.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.gduf.dao.SigninMapper;
import edu.gduf.dto.SigninVO;
import edu.gduf.entity.Signin;
import edu.gduf.service.SiginService;

@Service
public class SiginServiceImp implements SiginService {
	@Autowired
	private SigninMapper signinMapper;
	// @Override
	// public List<Signin> getSignInfo(int pageNum, int pageSize, int tId, Date
	// starttime) {
	// PageHelper.startPage(pageNum, pageSize);
	// return signinMapper.selectSignInfo(tId, starttime);
	//
	// }

	@Override
	public int insert(Signin signin) {

		return signinMapper.insert(signin);
	}

	@Override
	public int update(long signintime, long starttime, long endtime, int tId, int stuId) {
		System.out.println(starttime);
		System.out.println(signintime);
		System.out.println(endtime);
		if (signintime >= starttime && signintime <= endtime) {
			System.out.println("insert 333333333333333");
			int res = signinMapper.updateSign(signintime, starttime, tId, stuId);
			System.out.println("res:" + res);
			return res;

		}
		return 0;
	}

	@Override
	public List<SigninVO> listSignin(int tId) {
		List<Signin> signins =  signinMapper.selectList(tId, null, null);
		List<SigninVO>  signinVOS = new ArrayList<>();
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for(Signin signin : signins) {
			SigninVO signinVO = new SigninVO();
			signinVO.setStuId(signin.getStuId());
			signinVO.setName(signin.getStuName());
			if(signin.getSigntime() != null) {
				signinVO.setSignintime(format.format(signin.getSigntime()));
			}
			// signinVO.setStatus(signin.getStatus());
			signinVOS.add(signinVO);
		}
		return signinVOS;
	}

}
